/*
探索C++对象模型
*/
#include <iostream>
using namespace std;

class A {
public:
  ~A() {}
};

class B : public A {
};

class C : public A {
public:
  virtual ~C() {}
};

class D : virtual public A {
};

class E : virtual public A {
};

class F : public B, public C {
};

class G : public D, public E {
};

int main() {
  cout << "sizeof(A): " << sizeof(A) << endl;
  cout << "sizeof(B): " << sizeof(B) << endl;
  cout << "sizeof(C): " << sizeof(C) << endl;
  cout << "sizeof(D): " << sizeof(D) << endl;
  cout << "sizeof(E): " << sizeof(E) << endl;
  cout << "sizeof(F): " << sizeof(F) << endl;
  cout << "sizeof(G): " << sizeof(G) << endl;
{
  F f, *pt = &f;
  B* pb = dynamic_cast<B*>(pt);
  C* pc = dynamic_cast<C*>(pt);
  cout << "pt: " << pt << endl;
  cout << "pb: " << pb << endl;
  cout << "pc: " << pc << endl;
  cout << "bA: " << dynamic_cast<A*>(pb) << endl;
  cout << "cA: " << dynamic_cast<A*>(pc) << endl;
}
{
  G g, *pt = &g;
  D* pd = dynamic_cast<D*>(pt);
  E* pe = dynamic_cast<E*>(pt);
  cout << "pt: " << pt << endl;
  cout << "pd: " << pd << endl;
  cout << "pe: " << pe << endl;
  cout << "dA: " << dynamic_cast<A*>(pd) << endl;
  cout << "eA: " << dynamic_cast<A*>(pe) << endl;
}
}